package com.wzb.mybatisplus.bitaction.electrumaction;

import com.fasterxml.jackson.databind.JsonNode;

public class ElectrumClientExample {
    public static void main(String[] args) {
        // 使用公共Electrum服务器或本地运行的Electrum客户端
        ElectrumClient client = new ElectrumClient("127.0.0.1", 50001);

        try {
            // 连接服务器
            client.connect();

            // 测试连接
            boolean isAlive = client.ping();
            System.out.println("服务器状态: " + (isAlive ? "在线" : "离线"));

            // 获取服务器信息
            String version = client.getServerVersion();
            System.out.println("服务器版本: " + version);

            // 示例地址（替换为你要查询的地址）
            String testAddress = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa";

            // 获取余额
            ElectrumClient.BalanceInfo balance = client.getAddressBalance(testAddress);
            System.out.println("地址 " + testAddress + " 的余额:");
            System.out.println(balance.toString());

            // 获取交易历史
            JsonNode history = client.getAddressHistory(testAddress);
            System.out.println("交易历史: " + history);

            // 获取未花费输出
            JsonNode unspent = client.getUnspentOutputs(testAddress);
            System.out.println("未花费输出: " + unspent);

            // 估算费用
            double fee = client.estimateFee(6);
            System.out.println("6个区块确认的费用估算: " + fee + " BTC/kB");

        } catch (Exception e) {
            System.err.println("错误: " + e.getMessage());
            e.printStackTrace();
        } finally {
            // 断开连接
            client.disconnect();
        }
    }
}